﻿namespace DynamicQuartz.Web.Service
{
    public class LogService
    {
        public List<string> GetLogDirectories()
        {
            string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;

            var files = Directory.GetDirectories(Path.Combine(currentDirectory,"Log")).ToList();

            return files.ToList();
        }

        public List<string> GetLogFile(string path)
        {
            var files = Directory.GetFiles(path).ToList();
            return files;
        }


        public string Open(string path)
        {
            try
            {
                using (FileStream fileStream = File.Open(path, FileMode.Open, FileAccess.Read))
                {
                    // 在这里进行文件读取操作
                    // 例如，使用StreamReader读取文件内容
                    using (StreamReader reader = new StreamReader(fileStream))
                    {
                        string content = reader.ReadToEnd();
                        return content;
                    }
                }
            }
            catch (IOException ioEx)
            {
                return "IO Error: " + ioEx.Message;
            }
            catch (UnauthorizedAccessException uaEx)
            {
                return "Access Error: " + uaEx.Message;
            }
            catch (Exception ex)
            {
                return "General Error: " + ex.Message;
            }
        }
    }
}
